<template>
  <div class="myContailer">
    <el-row class="myTitleBorderBottom">
      <el-col :span="12" class="myLineHeight_40px">{{this.title}}</el-col>
      <el-col :span="12" class="myTextAlignRight">
        <el-button type="primary" class="myBgGreen" @click="add" v-if="isShow(217)">新 增</el-button>
        <!-- <el-button type="primary" class="myBgGreen">导出Excel</el-button> -->
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="6">
        <template>
          <el-cascader
            placeholder="全部项目/小区"
            :options="regionOptions"
            v-model="regionOptSelected"
          ></el-cascader>
        </template>
      </el-col>
      <el-col :span="4">
        <el-select v-model="devRoomSelected"
          clearable
          @visible-change="clickDevRoomSelect"
          :loading="loading"
          placeholder="请选择设备房">
          <el-option
            v-for="item in devRoomList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-col>
      <el-col :span="4">
        <el-input v-model="kw" placeholder="请输入关键字"></el-input>
      </el-col>
      <el-col :span="3">
        <el-button type="primary" class="myBgGreen" @click="fuzzySearch">查 询</el-button>
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="24">
        <el-table
          ref="multipleTable"
          :data="list"
          :border = true
          :stripe = true
          v-loading="loading"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            width="55">
          </el-table-column>
          <el-table-column
            type="index"
            label="序号"
             :index="indexMethod"
            width="100"
            >
          </el-table-column>
          <el-table-column
            prop="dev_room_name"
            width="150"
            label="所属设备房"
            >
          </el-table-column>
          <el-table-column
            prop="camera_no"
            width="120"
            label="摄像头编号"
            >
          </el-table-column>
          <el-table-column
            prop="camera_name"
            label="摄像头名称"
            >
          </el-table-column>
           <el-table-column
            prop="camera_did"
            width="150"
            label="摄像头DID"
            >
          </el-table-column>
           <el-table-column
            prop="camera_url"
            label="摄像头URL"
            >
          </el-table-column>
           <el-table-column
            prop="status"
            label="状态"
            width="100"
            >
            <template scope="scope">
              <span>{{scope.row.status| deviceStatus}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="area_name"
            label="所属小区"
            >
          </el-table-column>
          <el-table-column
            label="操作"
            width="100">
            <template scope="scope">
              <el-button @click="getDetail(scope.row.camera_id)" class="look" type="text" size="small">查看</el-button> |
              <el-button type="text primary" @click="modify(scope.row.camera_id)" class="modifly" size="small" v-if="isShow(218)">编辑</el-button>  
            </template>
          </el-table-column>
        </el-table>
        <div class="block">                    
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page_num"
            :page-sizes="[10, 15]"
            :page-size="page_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </el-col>
    </el-row>
  </div>
</template>  

<style scoped>
  .myContailer{
    background: #fff;
    padding: 10px;
  }
  .myTitleBorderBottom{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 1px solid #dbdbdb;
    padding-bottom: 5px;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top:2px;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myMarginTop_10px{
    margin-top: 10px;
  }
</style>

<script>
  import { extractAreaIds } from '@/utils/misc';
  import { getCameraList } from '@/api/camera';
  import { getDevRoomList } from '@/api/dev_room';
  import { getRegion } from '@/utils/localstorage';
  export default {
     data(){
      return{
        title: "摄像头管理",
        list:[],
        total:null, //总条数  
        page_num: 1, //当前页码
        page_size: 10, //每页显示多少条

        kw: null,
        tipText:"暂无数据",
        showTip:false,
        loading:false,
        lookObj:{},
        modifyNum:{},

        multipleSelection: [],
        regionOptions: [],
        regionOptSelected: [],

        devRoomList: [],
        devRoomSelected: null,
        devRoomLoaded: false
      }
    },
    components: {
        
    },
    created(){
      document.title=this.title;
      this.regionOptions = getRegion();
      this.regionOptSelected.push(this.regionOptions[0].value,this.regionOptions[0].children[0].value,this.regionOptions[0].children[0].children[0].value);
      
      this.fetchList();
    },
    computed: {
      areaIds() {
        return extractAreaIds(this.regionOptSelected, this.regionOptions);
      }
    },
    methods:{
       fetchList() {
        this.loading = true;
        let vm = this;
        let params = {
          dev_room_id: this.devRoomSelected,
          kw: this.kw,
          page_num: this.page_num,
          page_size: this.page_size
        }; 
        getCameraList(this.areaIds, params)
        .then(response => {
          let res = response.data;
          vm.list = res.rows;
          vm.total = res.total;
          vm.page_num = res.page_num;
          vm.page_size = res.page_size;

          vm.loading = false;
        }).catch(error => {
          vm.loading = false;
        })
      },
      fuzzySearch() {
         this.fetchList();
      },
      handleSizeChange(val) {
        this.page_size = val;
        this.fetchList();
      },
      handleCurrentChange(val) {
        this.page_num = val;
        this.fetchList();
      },
      deleteData:function (data,index) {
        this.data = data;
        this.index = index;
        this.lookObj = data.list[index]
      },
     
      getDetail(id){
        this.$router.push({
          path:'/jksbComonents',
          query: {type: 'info', id: id}
        })
      },
      add(){
        this.$router.push({
          path:'/jksbComonents',
          query: {type: 'add'}
        })
      },
      modify(id){
        this.$router.push({
          path:'/jksbComonents',
          query: {type: 'update', id: id}
        })
      },
      allCheck:function(){},
      
      sureDelete:function(event){
     
        this.list.splice(this.index, 1);

        /*提示信息*/
        Tips.init({
          type:"success",
          message:"删除成功",
          class:"on"
        });
       //optVue.sbfgl(this);
      },
    
      allDelete:function(event){
        console.log($(".checkboxes").is(':checked'))
        if($(".checkboxes").is(':checked')){
          
        }
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
        if(val.length!=0){
          for(var i = 0;i<val.length;i++){
            this.idArr.push(val[i].area_id)
          }
        }else{
          this.idArr = [];
        }
      },
      indexMethod(index) {
        return (this.page_num-1)*this.page_size + index + 1
      },
      clickDevRoomSelect(val) {
        console.log(this.devRoomLoaded);
        if (!val) {
          return;
        }

        let vm = this;
        const params = {
          ril: 'S',
          page_num: 1,
          page_size: 999
        };
        if (!this.devRoomLoaded) {
          getDevRoomList(this.areaIds, params)
          .then(response => {
            vm.devRoomList = response.data.rows;
            vm.devRoomLoaded = true;
          })
          .catch(error => {

          })
        }
      } 
    }

}
</script>  



